package com.mofang.ticketing.user.serve.account.controller;


import com.mofang.ticketing.common.core.dto.PrimaryIdDTO;
import com.mofang.ticketing.common.core.page.PageResult;
import com.mofang.ticketing.common.core.result.Result;
import com.mofang.ticketing.common.core.urls.user.account.AccountUrl;
import com.mofang.ticketing.common.log.SystemLog;
import com.mofang.ticketing.common.security.util.SecurityUtil;
import com.mofang.ticketing.user.serve.account.dto.request.*;
import com.mofang.ticketing.user.serve.account.dto.response.MerchantAccountListPageRespDTO;
import com.mofang.ticketing.user.serve.account.service.MerchantAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author LGC
 */
@Slf4j
@Api(tags = "商户账号管理")
@RestController
public class MerchantAccountController {

    @Resource
    private MerchantAccountService merchantAccountService;

    @ApiOperation(value = "商户账号分页列表")
    @PostMapping(value = AccountUrl.MERCHANT_ACCOUNT_LIST_PAGE)
    public Result<PageResult<MerchantAccountListPageRespDTO>> merchantAccountListPage(@RequestBody @Validated MerchantAccountListPageReqDTO dto) {
        return Result.page(PageResult.getPageResult(merchantAccountService.merchantAccountListPage(dto)));
    }

    @SystemLog
    @ApiOperation(value = "商户账号新增")
    @PostMapping(value = AccountUrl.MERCHANT_ACCOUNT_ADD)
    public Result<Void> merchantAccountAdd(@RequestBody @Validated MerchantAccountAddReqDTO dto) {
        merchantAccountService.merchantAccountAdd(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "商户账号修改")
    @PostMapping(value = AccountUrl.MERCHANT_ACCOUNT_UPDATE)
    public Result<Void> merchantAccountUpdate(@RequestBody @Validated MerchantAccountUpdateReqDTO dto) {
        merchantAccountService.merchantAccountUpdate(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "商户账号禁用启用")
    @PostMapping(value = AccountUrl.MERCHANT_ACCOUNT_ENABLE)
    public Result<Void> merchantAccountEnable(@RequestBody @Validated PrimaryIdDTO dto) {
        merchantAccountService.merchantAccountEnable(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "商户账号重置密码")
    @PostMapping(value = AccountUrl.MERCHANT_ACCOUNT_RESET_PWD)
    public Result<Void> merchantAccountResetPwd(@RequestBody @Validated PrimaryIdDTO dto) {
        merchantAccountService.merchantAccountResetPwd(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "商户账号删除")
    @PostMapping(value = AccountUrl.MERCHANT_ACCOUNT_DEL)
    public Result<Void> merchantAccountDel(@RequestBody @Validated PrimaryIdDTO dto) {
        merchantAccountService.merchantAccountDel(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "商户账号设置修改密码")
    @PostMapping(value = AccountUrl.MERCHANT_ACCOUNT_UPDATE_PWD)
    public Result<Void> merchantAccountUpdatePwd(@RequestBody @Validated AccountUpdatePwdReqDTO dto) {
        merchantAccountService.merchantAccountUpdatePwd(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "商户账号设置修改手机号（账号）")
    @PostMapping(value = AccountUrl.MERCHANT_ACCOUNT_UPDATE_PHONE)
    public Result<Void> merchantAccountUpdatePhone(@RequestBody @Validated AccountUpdatePhoneReqDTO dto) {
        merchantAccountService.merchantAccountUpdatePhone(dto, SecurityUtil.getUserId());
        return Result.success();
    }
}
